<ListBox x:Class="TagFlo.PhotoGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		 xmlns:c="clr-namespace:TagFlo"
	xmlns:sys="clr-namespace:System;assembly=mscorlib"
    
		 ScrollViewer.CanContentScroll="False"
					ScrollViewer.HorizontalScrollBarVisibility="Disabled"
						 
					ItemTemplate="{DynamicResource PhotoItemTemplate}"
						 
					Margin="0"
					SelectionMode="Extended" Style="{DynamicResource PhotoListBoxStyle}"
					>



        <ListBox.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Resources\ResourceDictionary.xaml"/>
                <ResourceDictionary Source="..\Resources\ControlStyle.xaml"/>
                <ResourceDictionary Source="..\Themes\current.theme.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="PhotoListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Border  Name="Border"  Padding="2" SnapsToDevicePixels="true">
                                <ContentPresenter />
                            </Border>

                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="true">
                                    <!--<Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>-->

                                    <Setter TargetName="Border" Property="BitmapEffect">
                                        <Setter.Value>
                                            <OuterGlowBitmapEffect GlowColor="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" GlowSize="10" />
                                        </Setter.Value>

                                    </Setter>
                                </Trigger>

                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


            <Style x:Key="PhotoListBoxStyle" TargetType="{x:Type ListBox}">
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />


                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ItemsControl}">
                            <ScrollViewer CanContentScroll="True">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <c:PhotoCollectionOrderBy x:Key="PhotoCollectionOrderBy"/>

            <c:ExposureModeConverter x:Key="ExposureModeConverter"/>
            <c:FocalLengthConverter x:Key="FocalLengthConverter"/>
            <c:LensApertureConverter x:Key="LensApertureConverter"/>
            <c:ExposureTimeConverter x:Key="ExposureTimeConverter"/>
            <c:WhiteBalanceConverter x:Key="WhiteBalanceConverter"/>
            <c:RatingConverter x:Key="RatingConverter"/>
            <c:DateConverter x:Key="DateConverter"/>
            <c:IsoSpeedConverter x:Key="IsoSpeedConverter"/>
          
            <DataTemplate x:Key="PhotoItemTemplate">
                <Grid Width="175" Height="175"	VerticalAlignment="Center" HorizontalAlignment="Center" Margin="6">
                    <Border Padding="4"  BorderBrush="#22000000" Background="White" BorderThickness="1" CornerRadius="4"  >
                        <Border.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Open" Click="PhotoItemMenuOpen_Click"/>
                                <MenuItem Header="Edit" Click="PhotoItemMenuEdit_Click"/>
                            </ContextMenu>
                        </Border.ContextMenu>
                        <StackPanel >
                            <Image Source="{Binding Path=Thumbnail}" Width="150" Height="150"  >
                            </Image>


                            <TextBlock x:Name="PhotoItemText" HorizontalAlignment="Right" Margin="0,0,10,0" FontSize="10"  Foreground="{StaticResource ForegroundBrush}" >
							<TextBlock.Text>
								<Binding Mode="OneWay" Path="DateTaken" Converter="{StaticResource DateConverter}" />
							</TextBlock.Text>
                            </TextBlock>
                            <!--"{Binding Path=Rating}" Background="White"-->
                            <!--Background="{Binding Path=Rank, Converter={StaticResource MyConverter}}"-->
                        </StackPanel>

                    </Border>


                </Grid>

                <DataTemplate.Triggers>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>Date</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=DateTaken,Converter={StaticResource DateConverter}}"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>Rating</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=Rating, Converter={StaticResource RatingConverter}}"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>IsoSpeed</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=IsoSpeed, Converter={StaticResource IsoSpeedConverter} }"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>ExposureTime</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=ExposureTime, Converter={StaticResource ExposureTimeConverter}}"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>FocalLength</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=FocalLength, Converter={StaticResource FocalLengthConverter}}"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>LensAperture</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=LensAperture, Converter={StaticResource LensApertureConverter}}"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>CameraModel</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=CameraModel }"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>Width</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=Width }"/>
                    </DataTrigger>

                    <DataTrigger>
                        <DataTrigger.Binding>
                            <Binding Source="{StaticResource PhotoCollectionOrderBy}" Mode="OneWay" Path="OrderBy"/>
                        </DataTrigger.Binding>
                        <DataTrigger.Value>
                            <sys:String>Height</sys:String>
                        </DataTrigger.Value>
                        <Setter TargetName="PhotoItemText" Property="Text" Value="{Binding Mode=OneWay, Path=Height }"/>
                    </DataTrigger>
                </DataTemplate.Triggers>


            </DataTemplate>
        </ResourceDictionary>
    </ListBox.Resources>
	<ListBox.ItemsPanel>
		<ItemsPanelTemplate>
			<c:VirtualizingTilePanel ChildSize="210"/>
		</ItemsPanelTemplate>
	</ListBox.ItemsPanel>
</ListBox>
